home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / expressionEdTextEditor.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  26.1 KB  |  997 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  ==================== expressionEdTextEditor.mel ==========
  22. //
  23. //  SYNOPSIS
  24. //
  25. //  CONTENTS
  26. //        (The procs are in the file in the order listed here.)
  27. //
  28. //  Expression Editor Text Editor and FAM handling routines
  29. //
  30. //  EEsetActualFileName       Replace "|" in object/filenames with "#".
  31. //  EEgetInternalFileName       Replace "#" in filenames with "|"
  32. //
  33. //    EEdoLaunch                Do the launch of the user's text editor of choice.
  34. //
  35. //    EElaunchEditor            Launch a text editor for a regular expression.
  36. //    EElaunchParticleEditor    Launch a text editor for a particle expression
  37. //  EEupdateFileExpression  Update a regular expression from a text editor file.
  38. //  EEupdateParticleFileExpression  Update a particle expression from a text
  39. //                                    editor file.
  40. //  EEdeleteStringElement    Delete an element from a string array.
  41. //  EEdeleteIntElement        Delete an element from an int array.
  42. //  EEexpressionIsInTextEditor Return whether an expression is in a text editor.
  43.  
  44. //    EEgetFileExpression        Callback from TexprEdFamAction.cc when the user
  45. //                            writes text editor file to disk.  Read file.
  46. //  EEdeleteEditorFile        Callback from TexprEdFamAction.cc when user
  47. //                          dismisses a text editor.  Delete the file.
  48.  
  49. // ******************************************************************
  50. //
  51. //                    GLOBAL VARIABLES FOR THE TEXT EDITOR MGMT
  52. //
  53. // ******************************************************************
  54. // 
  55.  
  56. // The next 4 lists are parallel, and have all the data necessary for
  57. // building a regular expression command.  
  58. // EEcurrFiles is the filenames of all files in text editors that are
  59. // creating/editing regular expressions.  EEcurrFileExprName is the name
  60. // of the expression being create/edited (which might not be the name
  61. // of the expression.  It may contain "" if there is no
  62. // name yet for an expression being created.  EEcurrFileCreateMode contains
  63. // the create/edit mode of the expression being edited in each editor.
  64. // EEcurrFileDefObj contains the default object, if any, of the expression
  65. // being edited/created.  
  66. //
  67. global string $EEcurrFiles[];
  68. global string $EEcurrFileExprName[];
  69. global int      $EEcurrFileCreateMode[];   // 1 = creating; 0 = editing
  70. global string $EEcurrFileDefObj[];
  71.  
  72. // Count of default filenames. 
  73. //
  74. global int      $EEdefFilenameCount = 0;
  75.  
  76.  
  77. // ******************************************************************
  78. //
  79. //            EXPRESSION EDITOR TEXT EDITOR PROCEDURES
  80. //
  81.  
  82. //  ================ EEsetActualFileName ================
  83. //
  84. //  SYNOPSIS
  85. //        Since unix will not correctly handle the "|" character in a filename,
  86. //        we have to switch it to something else, so let's use "#".  
  87. //
  88. proc string  EEsetActualFileName(string $fileName)
  89. {
  90.     // We can't use "subsitute()", because it finds only the first instance
  91.     // in the string.  So, tokenize based on "|", and then re-constitute
  92.     // the parts with a # in between each token.
  93.  
  94.     if (size($fileName) == 0)
  95.         return $fileName;
  96.  
  97.     // Make sure to not lose an initial "|"
  98.     //
  99.     string $finalFileName;
  100.     string $firstChar = substring($fileName, 1, 1);
  101.  
  102.     if ($firstChar == "|")
  103.     {
  104.         $finalFileName = "#";
  105.     }
  106.  
  107.     string $buffer[];
  108.     int $numTokens = tokenize($fileName, "|", $buffer);
  109.  
  110.     $finalFileName = $finalFileName + $buffer[0];
  111.     for ($i = 1; $i < $numTokens; $i++)
  112.     {
  113.         $finalFileName = $finalFileName + "#" + $buffer[$i];
  114.     }
  115.  
  116.     return $finalFileName;
  117. }
  118.  
  119.  
  120. //  ================ EEgetInternalFileName ================
  121. //
  122. //  SYNOPSIS
  123. //        There may be grouping and non-unique names, in which there
  124. //        will be "|" characters in the object name.  But since we can't use
  125. //        "|" in unix file names, we switched them to "#" for the filename.
  126. //        So now switch back to get to the object/expression name again.
  127. //
  128. global proc string    EEgetInternalFileName(string $fileName)
  129. {
  130.     if (size($fileName) == 0)
  131.         return $fileName;
  132.  
  133.     // Make sure to not lose an initial "#"
  134.     //
  135.     string $finalFileName;
  136.     string $firstChar = substring($fileName, 1, 1);
  137.  
  138.     if ($firstChar == "#")
  139.     {
  140.         $finalFileName = "|";
  141.     }
  142.  
  143.     string $buffer[];
  144.     int $numTokens = tokenize($fileName, "#", $buffer);
  145.  
  146.     $finalFileName = $buffer[0];
  147.     for ($i = 1; $i < $numTokens; $i++)
  148.     {
  149.         $finalFileName = $finalFileName + "|" + $buffer[$i];
  150.     }
  151.  
  152.     return $finalFileName;
  153. }
  154.  
  155.  
  156. //  ================ EEdoLaunch ================
  157. //
  158. //  SYNOPSIS
  159. //      Launch the desired text editor.
  160. //
  161. global proc EEdoLaunch(string $exprFile, string $expression)
  162. {
  163.     global int $EEcurrentEditor;
  164.     int $crFI;
  165.     int $win32 = `exists Win32Init`;
  166.     int $OSMac = `about -mac`;
  167.  
  168.     string $finalFileName = EEsetActualFileName($exprFile);
  169.     $exprFile = $finalFileName;
  170.  
  171.     // Open the temp file in which the user will edit the expression.
  172.     //
  173.     $crFI = fopen($exprFile, "wt" );
  174.     if (size($expression))
  175.     {
  176.         fprint($crFI, $expression+"\n");
  177.     }
  178.     fclose($crFI);
  179.  
  180.     // When invoking the editor 2 commands will be issued:  one to invoke
  181.     // the editor, and the other to delete a file, so, since xwsh allows
  182.     // only one command, we have to combine them into a script and have
  183.     // xwsh execute that script.  The file to be deleted will be just this
  184.     // executable script. The reason for this is that the expression editor
  185.     // has to know when the user quits the text editor, in order to clean
  186.     // up the temporary files.  So when the command script (filename.EXE)
  187.     // is deleted (by itself) this cues the editor to do the cleanup.
  188.     //
  189.     // Set the command script name and contents, open the command script
  190.     // file, write the commands to it, and make it executable.
  191.     //
  192.     string $edCmdString;
  193.     if (`about -irix`)
  194.     {
  195.         string $winEditor;
  196.         string $buffer[];
  197.  
  198.         string $shellCmd = "xwsh -geometry 60x24+0+0 -name " + $exprFile + " -e " ;
  199.         switch($EEcurrentEditor)
  200.         {
  201.             case 2:    $edCmdString = "jot -f -p 0,540,1023,640 ";
  202.                     break;
  203.             case 3:    $edCmdString = $shellCmd + "vi";
  204.                     break;
  205.             case 4:    $edCmdString = "vim -gf";
  206.                     break;
  207.             case 5:    $edCmdString = $shellCmd + "xemacs -nw";
  208.                     break;
  209.             case 6:    $edCmdString = getenv("WINEDITOR");
  210.                     tokenize($edCmdString, " ", $buffer);
  211.                     break;
  212.         }
  213.     }
  214.     if (`about -linux`)
  215.     {
  216.         string $winEditor;
  217.         string $buffer[];
  218.  
  219.         string $shellCmd = "xterm -geometry 60x24+0+0 -name " + $exprFile + " -e " ;
  220.         switch($EEcurrentEditor)
  221.         {
  222.             case 2:    $edCmdString = "emacs";
  223.                     break;
  224.             case 3:    $edCmdString = "gvim -f";
  225.                     break;
  226.             case 4:    $edCmdString = $shellCmd + "vi";
  227.                     break;
  228.             case 5:    $edCmdString = $shellCmd + "vim";
  229.                     break;
  230.             case 6:    $edCmdString = "xedit";
  231.                     break;
  232.             case 7:    $edCmdString = "xemacs";
  233.                     break;
  234.             case 8:    $edCmdString = getenv("WINEDITOR");
  235.                     tokenize($edCmdString, " ", $buffer);
  236.                     break;
  237.         }
  238.     }
  239.  
  240.     string $exeFile;
  241.     string $fileCmds; 
  242.  
  243.     if ($win32==1)
  244.     {
  245.         $exeFile = $exprFile + ".BAT";
  246.         $exeFile = toNativePath($exeFile);
  247.         $fileCmds = "start /WAIT " + $exprFile + "\ndel " + $exeFile;
  248.     }
  249.     else if($OSMac == 1)
  250.     {
  251.         print ("Not yet implemented for Mac\n");
  252.     }
  253.     else
  254.     {
  255.         $exeFile = $exprFile + ".EXE";
  256.         $fileCmds = $edCmdString + " " + $exprFile+";\nrm " + $exeFile + ";";
  257.     }
  258.  
  259.     int $exeFI = fopen ($exeFile, "wt");
  260.     fprint($exeFI, $fileCmds);
  261.     fclose ($exeFI);
  262.  
  263.     if ($win32==0 && $OSMac == 0)
  264.     {
  265.         system("chmod +x " + $exeFile);   // gg: unix only
  266.     }
  267.  
  268.     // Build the xwsh command that will launch the editor.
  269.     //
  270.     // Well, don't build it for jot or vim, because they is not going
  271.     // to go in the shell, and we end up with 2 windows.  And if users
  272.     // use WINEDITOR, they are on their own.
  273.     //
  274.     string $edCmd;
  275.  
  276.     $edCmd = $exeFile;
  277.  
  278.     // Tell TexprEdListenAction to listen for changes to the text
  279.     // file and the command file.  This will register these files to
  280.     // be monitored by FAM.
  281.     //
  282.     expressionEditorListen -lf $exeFile;
  283.     expressionEditorListen -lf $exprFile;
  284.  
  285.     // Launch the editor.
  286.     //
  287.     if ($win32==1)    {
  288.         system("shell " +$edCmd+">nul: 2>&1");  // GG: NT only
  289.     }
  290.     else {
  291.         system($edCmd+">/dev/null 2>&1 &");   // GG: unix only
  292.     }
  293.  
  294. }    // EEdoLaunch
  295.  
  296.  
  297. //  ================ EElaunchEditor ================
  298. //
  299. //  SYNOPSIS
  300. //      Set up to launch a text editor for a regular expression.
  301. //
  302. global proc    EElaunchEditor( string $fileName, 
  303.                             string $expression, 
  304.                             string $expressionName)
  305. {
  306.     global int    $EEcreateMode;
  307.     global int      $EEdefFilenameCount;
  308.     global string $EEcurrFiles[];
  309.     global string $EEcurrParticleFiles[];
  310.     global string $EEcurrFileExprName[];
  311.     global string $EEcurrFileDefObj[];
  312.     global int      $EEcurrFileCreateMode[]; 
  313.     global int    $EEexpressionInEditor;
  314.     global int    $EEpExpressionInEditor;
  315.     global string $EEnodeMode;
  316.  
  317.     int $fileNum = size($EEcurrFiles);
  318.  
  319.     int $win32 = `exists Win32Init`;
  320.     int $OSMac = `about -mac`;
  321.     
  322.     string $exprFile;
  323.  
  324.     //    If scriptNodes were used, create a unique script ID from the
  325.     //    passed as the $expressionName argument.
  326.     //
  327.     if ($EEnodeMode == "scriptNode")
  328.     {
  329.         $expressionName = EEgetFullScriptName($expressionName);
  330.     }
  331.  
  332.     // Set the name of the temp file the expression will be edited
  333.     // in.  Since there may not be an expression name yet, and the
  334.     // expression name may change, give the file a "dummy" name,
  335.     // "exprFile<#>".  Also, keep track of the name of the expression
  336.     // being edited in each file and the default object name, if 
  337.     // there is one, for initial creation of an expression.
  338.     // 
  339.     //
  340.     if (size($expressionName))
  341.     {
  342.         int $index = EEexpressionIsInTextEditor($expressionName, 0);
  343.         if ($index > -1)
  344.         {
  345.             $EEexpressionInEditor =  $index;
  346.             $EEpExpressionInEditor = -1;
  347.             warning("The current expression is already in a text editor.");
  348.             return;
  349.         }
  350.         else
  351.         {
  352.             $EEcurrFileExprName[$fileNum] = $expressionName;
  353.         }
  354.     }
  355.     else
  356.     {
  357.         $EEcurrFileExprName[$fileNum] = "";
  358.     }
  359.  
  360.     string $tmpDir;
  361.  
  362.     if ($win32 || $OSMac)
  363.         $tmpDir = getenv ("TMPDIR");
  364.     else
  365.         $tmpDir = "/tmp";
  366.  
  367.     if (size($fileName) > 0)
  368.     {
  369.         $exprFile = $tmpDir + "/" + $fileName;
  370.     }
  371.     else
  372.     {
  373.         $EEdefFilenameCount += 1;
  374.         $exprFile = $tmpDir + "/exprFile" + $EEdefFilenameCount;
  375.     }
  376.  
  377.     // Look through the current list of files and make sure this
  378.     // name is not already there.  It could be there, but for
  379.     // another expression.  Yes, this is dumb, but there you are.
  380.     //
  381.     int $i, $found, $count = 0;
  382.     int $done = 0;
  383.     string $tmpFile = $exprFile;
  384.  
  385.     while (!$done)
  386.     {
  387.         $found = 0; 
  388.  
  389.         for ($i = 0; $i < size($EEcurrFiles); $i++)
  390.         {
  391.             if ($EEcurrFiles[$i] == $tmpFile)
  392.             {
  393.                 $tmpFile = $exprFile + "." + ($count + 2);
  394.                 $found = 1;
  395.                 $count++;
  396.                 break;
  397.             }
  398.         }
  399.         if (!$found)
  400.             $done = 1;
  401.     }
  402.     $exprFile = $tmpFile;
  403.  
  404.     if (`exists Win32Init`)
  405.     {
  406.         $exprFile = $exprFile + ".TXT";
  407.     }
  408.  
  409.     // Set a pointer to where in the list of expressions in text editors,
  410.     // the current expression in the Expression Editor is.  Add the
  411.     // current expression to the list.  Need to keep track of the file
  412.     // name and whether in edit or create mode
  413.     //
  414.     $EEexpressionInEditor =  $fileNum;
  415.     $EEpExpressionInEditor = -1;
  416.  
  417.     $EEcurrFileCreateMode[$fileNum] = $EEcreateMode;
  418.     $EEcurrFiles[$fileNum] = $exprFile;
  419.  
  420.     if (`window -exists "expressionEditorWin"`)
  421.     {
  422.         string $defaultObj = `textFieldGrp -q -text EEdefNameT`;
  423.         $EEcurrFileDefObj[$fileNum] = $defaultObj;
  424.     }
  425.     else
  426.     {
  427.         if (size($expressionName) == 0)
  428.         {
  429.            $EEcurrFileCreateMode[$fileNum] = 1;
  430.            $EEcreateMode = 1;
  431.         }
  432.         else
  433.         {
  434.            $EEcurrFileCreateMode[$fileNum] = 0;
  435.            $EEcreateMode = 0;
  436.         }
  437.     }
  438.  
  439.     // Now launch the text editor.
  440.     //
  441.     EEdoLaunch($exprFile, $expression);
  442.  
  443. }    // EElaunchEditor
  444.  
  445.  
  446. //  ================ EElaunchParticleEditor ================
  447. //
  448. //  SYNOPSIS
  449. //      Set up to launch a text editor for a particle expression.
  450. //
  451. global proc    EElaunchParticleEditor( string $expression, string $particleName)
  452. {
  453.     global int $EEisRuntime;
  454.     global string $EEcurrParticleFiles[];
  455.     global int $EEpExpressionInEditor;
  456.     global int $EEexpressionInEditor;
  457.  
  458.     int $index = EEexpressionIsInTextEditor($particleName, 1);
  459.  
  460.     if ($index > -1)
  461.     {
  462.         $EEexpressionInEditor =  -1;
  463.         $EEpExpressionInEditor = $index;
  464.         warning("The current expression is already in a text editor.");
  465.         return;
  466.     }
  467.  
  468.     // Set a pointer to where in the list of expressions in text editors,
  469.     // the current expression in the Expression Editor is.  Add the
  470.     // current expression to the list.
  471.     //
  472.     int $win32 = `exists Win32Init`;
  473.     int $OSMac = `about -mac`;
  474.     string $tmpDir;
  475.     if ($win32 || $OSMac)
  476.         $tmpDir = getenv("TMPDIR");
  477.     else
  478.         $tmpDir = "/tmp";
  479.  
  480.     string $exprFile = $tmpDir + "/" + $particleName;
  481.  
  482.     if ($EEisRuntime)
  483.         $exprFile = $exprFile + ".runtime";
  484.     else
  485.         $exprFile = $exprFile + ".creation";
  486.  
  487.     if ($win32 || $OSMac)
  488.         $exprFile = $exprFile + ".TXT";
  489.  
  490.     $EEpExpressionInEditor = size($EEcurrParticleFiles);
  491.     $EEexpressionInEditor = -1;
  492.     $EEcurrParticleFiles[size($EEcurrParticleFiles)] = $exprFile;
  493.  
  494.     // Launch the text editor.
  495.     //
  496.     // Set up the filename for the temp file to edit the expression in.
  497.     //
  498.     EEdoLaunch($exprFile, $expression);
  499.  
  500. }    // EElaunchParticleEditor
  501.  
  502.  
  503.  
  504. //  ================ EEupdateFileExpression ================
  505. //
  506. //  SYNOPSIS
  507. //      A text editor file has been written.  So get its contents
  508. //        and update the expression and the Expression Editor.
  509. //
  510. global proc    EEupdateFileExpression(string $fileName, 
  511.                                    string $expression, int $isCurrent)
  512. {
  513.     global string $EEcurrFiles[];
  514.     global string $EEcurrFileExprName[];
  515.     global string $EEcurrFileDefObj[];
  516.     global int      $EEcurrFileCreateMode[];   // 1 = creating; 0 = editing
  517.     global int $EEeditedInEditor;
  518.  
  519.     string $newExprName;
  520.  
  521.     // Find the file in the list.
  522.     //
  523.     int $i, $index = -1;
  524.  
  525.     for ($i = 0; $i < size($EEcurrFiles); $i++)
  526.     {
  527.         if ($fileName == $EEcurrFiles[$i])
  528.         {
  529.             $index = $i;
  530.             break;
  531.         }
  532.     }
  533.  
  534.     if ($index == -1)
  535.         return;
  536.  
  537.     // Find out if editing or creating this expression.
  538.     //
  539.     int $creating = $EEcurrFileCreateMode[$index];
  540.  
  541.     // Make sure the expression can get through MEL.
  542.     //
  543.     string $newExprName;
  544.  
  545.     if ($creating)
  546.     {
  547.         // If creating and the expression is currently in the Expression
  548.         // Editor, need to do other flags as well, so call the same
  549.         // procedure as when selecting the create button.
  550.         // Otherwise just edit the expression itself..
  551.         //
  552.         // Don't try to make an expression node if there's no expression.
  553.         //
  554.         if ($expression == "")
  555.             return;
  556.  
  557.         if ($isCurrent)
  558.         {
  559.             $newExprName = EEapplyExpression($expression);
  560.  
  561.             $EEcurrFileExprName[$index] = $newExprName;
  562.  
  563.             // Re-call EEdisplayExpression now that the expression name is
  564.             // in $EEcurrFileExprName.  Otherwise the editor thinks it is
  565.             // not in text editor mode.
  566.             //
  567.             EEdisplayExpression($newExprName);
  568.         }
  569.         else
  570.         {
  571.             if (size($EEcurrFileDefObj[$index]))
  572.             {
  573.                 string $theCommand = ("expression -s \""+encodeString($expression)+"\" -o "+$EEcurrFileDefObj[$index]+";");
  574.                 $newExprName = evalEcho( $theCommand );
  575.             }
  576.             else
  577.             {
  578.                 string $theCommand = ("expression -s \""+encodeString($expression)+"\";");
  579.                 $newExprName = evalEcho( $theCommand );
  580.             }
  581.             $EEcurrFileExprName[$index] = $newExprName;
  582.         }
  583.  
  584.         // No longer in create mode.
  585.         //
  586.         $EEcurrFileCreateMode[$index] = 0;
  587.  
  588.  
  589.     }
  590.     else
  591.     {
  592.         // Editing.  So just edit the expression, and update the
  593.         // Expression Editor scroll field.
  594.         //
  595.         string $theCommand = ("expression -e -s \"" + encodeString($expression) +"\" " + $EEcurrFileExprName[$index] + ";");
  596.         $newExprName = evalEcho( $theCommand );
  597.  
  598.         if ($isCurrent)
  599.         {
  600.             $EEeditedInEditor = 1;
  601.             scrollField -e -text $expression EEmultiText;
  602.         }
  603.     }
  604.  
  605. }    // EEupdateFileExpression
  606.  
  607.  
  608. //  ================ EEupdateParticleFileExpression ================
  609. //
  610. //  SYNOPSIS
  611. //      A text editor file has been written.  So get its contents
  612. //        and update the expression and the Expression Editor.
  613. //
  614. global proc    EEupdateParticleFileExpression(string $fileName, 
  615.                                             string $expression,
  616.                                             int $isCurrent)
  617. {
  618.     string $buffer[];
  619.  
  620.     //    The filename for particle expression is composed of:
  621.     //  /tmp/<obj>.runtime/create.  So get the individual tokens.
  622.     //
  623.     tokenize ($fileName, ".", $buffer);
  624.     string $temp = $buffer[0];
  625.     string $runCreate = $buffer[1];
  626.     tokenize($temp, "/", $buffer);
  627.     string $nodeName = $buffer[size($buffer) - 1];
  628.  
  629.     string $exprReturn;
  630.  
  631.     if ($isCurrent)
  632.     {
  633.         // If the particle/expression is currently in the Expression
  634.         // Editor, do the same as if the "Create/Edit" button had been
  635.         // pressed.
  636.         //
  637.         EEapplyParticleExpression($expression);
  638.     }
  639.     else
  640.     {
  641.         int $isRuntime;
  642.         if ($runCreate == "runtime")
  643.             $isRuntime = 1;
  644.         else
  645.             $isRuntime = 0;
  646.  
  647.         // Edit the particle expression and Print the command to the
  648.         // command window.
  649.         //
  650.         EEdynExpressionCmd($isRuntime, $expression, $nodeName);
  651.     }
  652.  
  653. }    // EEupdateParticleFileExpression
  654.  
  655.  
  656.  
  657. //  ================ EEdeleteStringElement ================
  658. //
  659. //  SYNOPSIS
  660. //      Remove an element from a string array.
  661. //
  662. global proc string[] EEdeleteStringElement(string $array[], int $i)
  663. {
  664.     string $tmp[];
  665.     int $j;
  666.  
  667.     int $lastElemIndex = size($array) - 2;
  668.  
  669.     for ($j = 0; $j < $i; $j++)
  670.         $tmp[$j] = $array[$j];
  671.     
  672.     for ($j = $i; $j <= $lastElemIndex; $j++)
  673.         $tmp[$j] = $array[$j+1];
  674.  
  675.     return $tmp;
  676.  
  677. }    // EEdeleteStringElement
  678.  
  679.  
  680. //  ================ EEdeleteIntElement ================
  681. //
  682. //  SYNOPSIS
  683. //      Remove an element from an int array.
  684. //
  685. global proc int[] EEdeleteIntElement(int $array[], int $i)
  686. {
  687.     int $tmp[];
  688.     int $j;
  689.  
  690.     int $lastElemIndex = size($array) - 2;
  691.  
  692.     for ($j = 0; $j < $i; $j++)
  693.         $tmp[$j] = $array[$j];
  694.     
  695.     for ($j = $i; $j <= $lastElemIndex; $j++)
  696.         $tmp[$j] = $array[$j+1];
  697.  
  698.     return $tmp;
  699.  
  700. }    // EEdeleteIntElement
  701.  
  702.  
  703. //  ================ EEexpressionIsInTextEditor ================
  704. //
  705. //  SYNOPSIS
  706. //      Return whether the expression is already in a text editor.
  707. //
  708. global proc int EEexpressionIsInTextEditor(string $expressionName, int $isParticle)
  709. {
  710.     global int $EEisRuntime;
  711.     global string $EEcurrFiles[];
  712.     global string $EEcurrParticleFiles[];
  713.     global string $EEcurrFileExprName[];
  714.     global string $EEnodeMode;
  715.  
  716.     //    If scriptNodes were used, create a unique script ID from the
  717.     //    passed as the $expressionName argument.
  718.     //
  719.     if ($EEnodeMode == "scriptNode")
  720.     {
  721.         $expressionName = EEgetFullScriptName($expressionName);
  722.     }
  723.  
  724.     // Look through the list of expressions in text editors.  If this one
  725.     // is there, return its index in the list, otherwise return -1.
  726.  
  727.     if ($isParticle)
  728.     {
  729.         int $i;
  730.         string $exprFile = "/tmp/" + $expressionName;
  731.  
  732.         if ($EEisRuntime)
  733.             $exprFile = $exprFile + ".runtime";
  734.         else
  735.             $exprFile = $exprFile + ".creation";
  736.  
  737.         for ($i = 0; $i < size($EEcurrParticleFiles); $i++)
  738.         {
  739.             if ($exprFile == $EEcurrParticleFiles[$i])
  740.             {
  741.                 return $i;
  742.             }
  743.         }
  744.     }
  745.     else
  746.     {
  747.         for ($i = 0; $i < size($EEcurrFileExprName); $i++)
  748.         {
  749.             // Test for the filename, in EEcurrFileExprName.
  750.             //
  751.             if ($expressionName == $EEcurrFileExprName[$i])
  752.             {
  753.                 return $i;
  754.             }
  755.         }
  756.     }
  757.  
  758.     return -1;
  759.  
  760. }    // EEexpressionIsInTextEditor 
  761.  
  762.  
  763. // ******************************************************************
  764. //
  765. //                EXPRESSION EDITOR FAM "CALLBACKS" 
  766. //
  767. //
  768. //  ================ EEgetFileExpression ================
  769. //
  770. //  SYNOPSIS
  771. //      Get/read the expression from the temp file on disk.  This
  772. //        procedure is called from TexprEdFamListen (.cc), when FAM
  773. //        has signalled that the file has been modified.
  774. //
  775. global proc EEgetFileExpression(string $fileName)
  776. {
  777.     global int $EEcurrentEditor;
  778.     global string $EEcurrParticleFiles[];
  779.     global string $EEcurrFiles[];
  780.     global int      $EEpExpressionInEditor;
  781.     global int      $EEexpressionInEditor;
  782.     global string $EEnodeMode;
  783.  
  784.     string $expression;
  785.  
  786.     // Read the expression from the file.
  787.     //
  788.     int $fd = fopen($fileName, "rt");
  789.  
  790.     if ($fd == 0)
  791.     {
  792.         warning("ExpressionEditor: couldn't open "+$fileName);
  793.         return;
  794.     }
  795.  
  796.     string $tmpExpr;
  797.     for ($tmpExpr = ""; !`feof $fd`;)
  798.     {
  799.         $tmpExpr += fgetline ($fd);
  800.     }
  801.     fclose ($fd);
  802.  
  803.     int $lastIndex = size($tmpExpr);
  804.  
  805.     // If vi or vim, get rid of an odd character at the end of the file.
  806.     //
  807.  
  808.     if ($EEcurrentEditor == 3 || $EEcurrentEditor == 4
  809.         || (`about -linux` && $EEcurrentEditor == 5))
  810.     {
  811.         if (size($tmpExpr) > 2)
  812.             $tmpExpr = substring($tmpExpr, 1, $lastIndex - 1);
  813.     }
  814.  
  815.  
  816.     $expression = $tmpExpr;
  817.  
  818.     // There may be grouping and non-unique names, in which there
  819.     // will be "|" characters in the object name.  But since we can't use
  820.     // "|" in unix file names, we switched them to "#" for the filename.
  821.     // So now we have to switch back to get to the object/expression name again.
  822.     //
  823.     $internalFileName = EEgetInternalFileName($fileName);
  824.     $fileName = $internalFileName;
  825.  
  826.     // If this expression  is currently in the expression editor,
  827.     // update the text field, and find out if it is a particle.
  828.     //
  829.     int $expressionIsCurrent = 0;
  830.     int $nodeIsParticle = 0;
  831.  
  832.        if (`window -exists "expressionEditorWin"`)
  833.     {
  834.         if ($EEpExpressionInEditor >= 0)
  835.         {
  836.             if ($EEcurrParticleFiles[$EEpExpressionInEditor] == $fileName)
  837.             {
  838.                 $expressionIsCurrent = 1;
  839.                 $nodeIsParticle = 1;
  840.             }
  841.         }
  842.         else if ($EEexpressionInEditor >= 0)
  843.         {
  844.             if ($EEcurrFiles[$EEexpressionInEditor] == $fileName)
  845.             {
  846.                 $expressionIsCurrent = 1;
  847.             }
  848.         }
  849.  
  850.         if ($expressionIsCurrent)
  851.             scrollField -e -text $expression EEmultiText;
  852.     }
  853.  
  854.     // Update the expression node -- have to know if it is a
  855.     // particle or a regular expression.  
  856.     //
  857.     if (!$nodeIsParticle)
  858.     {
  859.         for ($i = 0; $i < size($EEcurrParticleFiles); $i++)
  860.         {
  861.             if ($fileName == $EEcurrParticleFiles[$i])
  862.             {
  863.                 $nodeIsParticle = 1;
  864.                 break;
  865.             }
  866.         }
  867.     }
  868.  
  869.     if ($nodeIsParticle)
  870.         EEupdateParticleFileExpression($fileName, $expression, $expressionIsCurrent);
  871.     else
  872.     {
  873.         if ($EEnodeMode == "scriptNode")
  874.             EEupdateFileScript($fileName, $expression, $expressionIsCurrent);
  875.         else
  876.             EEupdateFileExpression($fileName, $expression, $expressionIsCurrent);
  877.     }
  878.  
  879. }    // EEgetFileExpression
  880.  
  881.  
  882. //  ================ EEdeleteEditorFile ================
  883. //
  884. //  SYNOPSIS
  885. //      Delete a temp file from disk.  This procedure is called from
  886. //        TexprEdFamListen (.cc), when FAM has signalled that the .EXE
  887. //        file connected with this text file has been deleted.  Now
  888. //        need to delete this text file as well.
  889. //
  890. global proc EEdeleteEditorFile(string $fileName)
  891. {
  892.     global int $EEcurrentEditor;
  893.     global string $EEcurrParticleFiles[];
  894.     global string $EEcurrFiles[];
  895.     global string $EEcurrFileExprName[];
  896.     global string $EEcurrFileDefObj[];
  897.     global int      $EEcurrFileCreateMode[];   // 1 = creating; 0 = editing
  898.     global int      $EEpExpressionInEditor;
  899.     global int      $EEexpressionInEditor;
  900.  
  901.     sysFile -del $fileName;
  902.  
  903.     // There may be grouping and non-unique names, in which there
  904.     // will be "|" characters in the object name.  But since we can't use
  905.     // "|" in unix file names, we switched them to "#" for the filename.
  906.     // So now we have to switch back to get to the object/expression name again.
  907.     //
  908.     $internalFileName = EEgetInternalFileName($fileName);
  909.     $fileName = $internalFileName;
  910.  
  911.     // Remove the file from the list.
  912.     //
  913.     int $removed = 0;
  914.     int $i;
  915.     for ($i = 0; $i < size($EEcurrParticleFiles); $i++)
  916.     {
  917.         if ($fileName == $EEcurrParticleFiles[$i])
  918.         {
  919.             int $j;
  920.  
  921.             $EEcurrParticleFiles = EEdeleteStringElement($EEcurrParticleFiles, $i);
  922.             // If the deleted file holds the expression that is current
  923.             // in the editor, re-enable the expression textfield.
  924.             //
  925.             if ($EEpExpressionInEditor == $i)
  926.             {
  927.                 $EEpExpressionInEditor = -1;
  928.                 if (`window -exists "expressionEditorWin"`)
  929.                     scrollField -e -enable true EEmultiText;
  930.             }
  931.             else
  932.             {
  933.                 // If the current file index is greater than the index
  934.                 // of the element that got removed, decrement it by one.
  935.                 //
  936.                 if ($EEpExpressionInEditor > $i)
  937.                     $EEpExpressionInEditor -= 1;
  938.             }
  939.             $removed = 1;
  940.             break;
  941.         }
  942.     }
  943.     // If editor has been switched to Expression Editor while an expression
  944.     // is in a text editor, if this is the last file in the editor,
  945.     // then switch the scroll field back to enabled mode.
  946.     //
  947.     if (!$removed)
  948.     {
  949.         for ($i = 0; $i < size($EEcurrFiles); $i++)
  950.         {
  951.             if ($fileName == $EEcurrFiles[$i])
  952.             {
  953.                 $EEcurrFiles = EEdeleteStringElement($EEcurrFiles, $i);
  954.  
  955.                 $EEcurrFileExprName = 
  956.                         EEdeleteStringElement($EEcurrFileExprName, $i);
  957.  
  958.                 $EEcurrFileDefObj = 
  959.                         EEdeleteStringElement($EEcurrFileDefObj, $i);
  960.  
  961.                 $EEcurrFileCreateMode = 
  962.                         EEdeleteIntElement($EEcurrFileCreateMode, $i);
  963.  
  964.                 // If the deleted file holds the expression that is current
  965.                 // in the editor, re-enable the expression textfield.
  966.                 //
  967.                 if ($EEexpressionInEditor == $i)
  968.                 {
  969.                     if (`window -exists "expressionEditorWin"`)
  970.                         scrollField -e -enable true EEmultiText;
  971.                     $EEexpressionInEditor = -1;
  972.                 }
  973.             else
  974.             {
  975.                 // If the current file index is greater than the index
  976.                 // of the element that got removed, decrement it by one.
  977.                 //
  978.                 if ($EEexpressionInEditor > $i)
  979.                     $EEexpressionInEditor -= 1;
  980.             }
  981.                 break;
  982.             }
  983.         }
  984.     }
  985.  
  986.     if (`window -exists "expressionEditorWin"`)
  987.     {
  988.         if ($EEcurrentEditor == 1 && size($EEcurrFiles) == 0)
  989.             scrollField -e -enable true EEmultiText;
  990.     }
  991.  
  992. }    // EEdeleteEditorFile
  993.  
  994.  
  995.  
  996.  
  997.